
export const pro = (obj, pid) => {
  // 递归找法
  const res = []
  obj.forEach(v => {
    if (v.pid === pid) {
      const children = pro(obj, v.id)
      if (children.length > 0) {
        v.children = children
      }
      res.push(v)
    }
  })
  // console.log(res)
  // return res
  // 遍历
  // obj.forEach(v => {
  //   if (v.id !== pid) {
  //     const parent = obj.find(a => a.id === v.pid)
  //     if (parent) {
  //       parent.children = parent.children || []
  //       parent.children.push(v)
  //     }
  //   }
  // })
  return obj.filter(v => v.pid === pid)
}

